package com.itheima.Thread09;

import java.util.Objects;

public class MyThread extends Thread {
    private int piao = 100;
    private Object obj = new Object();

    @Override
    public void run() {
        while (true) {
            synchronized (obj) {
                if (piao == 0) {
                    break;
                } else {
                    try {
                        Thread.sleep(200);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    piao--;
                    System.out.println(Thread.currentThread().getName() + "在买票,还剩下" + piao + "张票");
                }
            }
        }
    }
}














